import 'package:flutter/material.dart';
import './playing_card.dart';
enum PlayerStatus {
  notReady,
  ready,
  getCard,
  isCallLandlord,
  callLandlord,
  notLandlord,
  isRobLandlord,
  robLandlord,
  notRobLandlord,
  firstHand,
  openHand,
  waiting,
  thinking,
  pass,
  emptyStatus,
  isRestart
}
enum PlayerRole {
  peasant,
  landlord
}

class Player {
  final String roleId;
  final String uname;
  final int sex;
  int asset;
  PlayerStatus status = PlayerStatus.notReady;
  List<String> lastCards = [];
  PlayerRole role =PlayerRole.peasant;
  final bool isMainRole;
  int countCards = 0;
  int maxCountCards = 0;
  int timer = 0;
  bool isLandlord;
  List cards = [];
  int countDown = 0;

  Player({@required this.roleId, @required this.isMainRole, this.isLandlord=false, @required this.uname, @required this.sex, @required this.asset});

  void setCountCard(int countCards) {
    this.countCards = countCards;
  }
  void setMaxCountCards(int maxCountCards) {
    this.maxCountCards = maxCountCards;
  }
  void triggerReady({bool isReady}) {
    this.status = isReady ? PlayerStatus.ready : PlayerStatus.notReady;
  }
  void triggerStatus(PlayerStatus status) {
    this.status = status;
    if(this.status == PlayerStatus.thinking) {
      this.lastCards = [];
    }
  }
  void setTimer() {
    this.timer = timer;
  }
  void setLandlord(bool isLandlord) {
    this.isLandlord = isLandlord;
  }
  void setCountDown(int countDown) {
    this.countDown = countDown;
  }
  void setAsset(int newAsset) {
    this.asset = newAsset;
  }

  void setCards(List _cards, {bool sort=false}) {
    cards = _cards;
    if(sort) {
      this.sortCards();
    }
  }
  void getCard(String _card) {
    cards.add(_card);
  }
  void getCards(List _cards) {
    cards.addAll(_cards);
  }
  void sortCards() {
    if(cards[0] != '') {
      Map keySort = PlayingCard.cards;
      cards.sort((left, right)=>keySort[right] - keySort[left]);
    }
  }
  void playCards(List<String> _cards) {}
}